package ollama

import (
	"os/exec"

	"github.com/spf13/cast"
)

func GetPortPid(port string) (int, error) {
	processInfo := exec.Command("/bin/sh", "-c", `lsof -i:`+port+` | awk '{print $2}' | awk  'NR==2{print}'`)
	output, err := processInfo.Output()
	if err != nil {
		return 0, err
	}
	strOpt := string(output)
	return cast.ToInt(strOpt), nil
}
